package pro.softzhang.algo.lc500;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * TODO 可优化
 */
public class LC539_MinimumTimeDifference {
    public static void main(String[] args) {
        List<String> timePoints = new ArrayList(){{
            add("23:59");
            add("00:00");
        }};
        int diff = new LC539_Solution().findMinDifference(timePoints);
        System.out.println(diff);
    }
}

class LC539_Solution {
    public int findMinDifference(List<String> timePoints) {
        if(timePoints.size() > 24 * 60) {
            return 0;
        }

        List<Integer> l = new ArrayList<>();
        for(String time : timePoints) {
            String[] strs = time.split(":");
            l.add(Integer.parseInt(strs[0]) * 60 + Integer.parseInt(strs[1]));
        }

        Collections.sort(l);

        // 为啥要在尾部加这个，没想明白。
        l.add(l.get(0) + 24 * 60);

        int diff = 24 * 60;
        for (int i = 1; i < l.size(); i++) {
            diff = Math.min(diff, l.get(i) - l.get(i - 1));
        }

        return diff;
    }
}

class LC539_Solution1 {
    public int findMinDifference(List<String> timePoints) {
        return -1;
    }
}